<template>
	<view>
		<!-- 若需显示自定义导航栏，需要在App.vue中引入Vue -->
		<cu-custom bgColor="bg-gradual-green" :isBack="true">
			<block slot="content">{{type == 1 ? '农产品列表' : '日用品列表'}}</block>
		</cu-custom>

		<scroll-view scroll-y="true">
			<view>
				<view class="goodsList">
					<view class="goodsItem" v-for="goods in goodsList" :id="goods.goodsId" hover-class="navigator-hover"
					 hover-stay-time="100" @click="itemClick">
						<view class="imgView" style="">
							<image style="width: 250upx; height: 180upx;border-radius: 20upx;" :src="'https://www.2306.tech/CCShop/images/goods/'+goods.goodsId+'/'+goods.goodsId+'-0.jpg'"
							 mode=""></image>
						</view>
						<view class="infoView">
							<view class="goodsName">{{goods.goodsName}}</view>
							<view class="goodsInfo">
								<view class="goodsBuyCount">已售：{{goods.goodsSoldAmount}}</view>
								<view class="goodsPrice text-price margin-left">{{goods.goodsPrice}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		getGoodsByType
	} from '../../api/goodsAPI.js'
	export default {

		data() {
			return {
				goodsList: [{
					"goodsImg": "images/goods/2000/2000-0.jpg;images/goods/2000/2000-1.jpg;",
					"goodsPromotePrice": 0.88,
					"goodsId": "2000",
					"goodsSupplyRange": "",
					"goodsOrigin": "河北 阜平",
					"goodsSoldAmount": 101,
					"goodsIsBackScore": 1,
					"goodsType": "",
					"goodsCategoryId": "1000",
					"goodsUseScoreMax": 1000,
					"goodsStartTime": null,
					"goodsStatus": -1,
					"goodsLowerLimit": 500,
					"goodsTotalAmount": 200,
					"goodsIsUseScore": 0,
					"goodsPrice": 3.98,
					"goodsIsHelper": 1,
					"goodsUnit": "斤",
					"goodsEndTime": null,
					"goodsIsPromote": 1,
					"goodsName": "大白菜",
					"goodsDescription": "多么新鲜的大白菜啊 ，刚刚采摘，非常新鲜",
					"goodsBackScoreAccount": 100
				}],
				type: 1
			}
		},
		methods: {
			itemClick(event) {
				console.log("event: ", event);
				let id = event.currentTarget.id
				uni.navigateTo({
					url: '../goodsDetail/goodsDetail?id=' + id
				})
			}
		},
		onLoad(params) {
			let type = params.type
			console.log("type: ", type);
			this.type = type
			
			if (null == type) {
				type = 1;
			}
			uni.showLoading({
				title: '加载中...'
			})
			getGoodsByType(type).then((resp) => {
				console.log("resp: ", resp);
				this.goodsList = resp
			})
		}
	}
</script>

<style>
	@import url("./goodsList.css");
</style>
